﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MedicareModel;
using MySql.Data.MySqlClient;

namespace MedicareDataAccess
{
    public class TriageDAO : DAOConnection
    {
        public static TriageDAO GetInstance()
        {
            return new TriageDAO();
        }

        public Triage getTriageByID(int idTriage)
        {
            MySqlCommand cm = DBGetCommand(string.Format("SELECT * FROM triage WHERE idTriage={0}", idTriage));
            MySqlDataReader dr = cm.ExecuteReader();
            if (!dr.Read())
            {
                cm.Connection.Close();
                return null;
            }

            Triage aTriage = new Triage();
            aTriage.idTriage = (int)dr["idTriage"];
            aTriage.colorCode = (string)dr["colorCode"];

            return aTriage;
        }

        public List<Triage> getAllTriage()
        {
            List<Triage> triages = new List<Triage>(); 
            MySqlCommand cm = DBGetCommand(string.Format("SELECT * FROM triage"));
            MySqlDataReader dr = cm.ExecuteReader();
            while (dr.Read())
            {
                Triage aTriage = new Triage(); 
                aTriage.idTriage = (int)dr["idTriage"];
                aTriage.colorCode = (string)dr["colorCode"];
                triages.Add(aTriage); 
            }

            cm.Connection.Close();
            return triages; 
        }

    }
}
